-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added getHash method in SQLFilter to avoid caching the filtered queries #8393
base: old-prototype-3.x
Are you sure you want to change the base?
Added getHash method in SQLFilter to avoid caching the filtered queries #8393
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Few change requests.
$hash = get_class($this).$parameterCount; | ||
foreach ($this->parameters as $name => $param) { | ||
if (is_object($param['value'])) { | ||
$valueHash = spl_object_hash($param['value']); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
spl_object_hash
is not reliable within and across requests. You need to serialize the parameter. the API of setParameter
only allows stirngs anyways, it is not enforced though. But that should allow us to do this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about changing this method to
final public function getHash()
{
return self::class.$this;
}
I don't think the serialize() will have a big performance impact here.
@@ -95,6 +95,17 @@ public function testGetFilter() : void | |||
|
|||
self::assertInstanceOf(MyFilter::class, $filterCollection->getFilter(self::TEST_FILTER)); | |||
} | |||
|
|||
public function testGetHash() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please also add an object based parameter and see serialize.
I introduced a new final method getHash on SQLFilter that generates a hash based on the called class name and all the parameters. Also the FilterCollection::getHash() was modified to use the getHash method from SQLFilter.
This is implemented acording to @beberlei's recomandation see the discussion bellow.
#3955 (comment)